package com.fr.web.platform.tables;

import com.fr.base.BaseUtils;
import com.fr.base.FRContext;
import com.fr.data.core.db.DBUtils;
import com.fr.data.core.db.dialect.DialectFactory;
import com.fr.data.core.db.dialect.SybaseDialect;
import com.fr.data.core.db.dml.Table;
import com.fr.data.core.db.tableObject.AbstractModuleTables;
import com.fr.data.core.db.tableObject.AbstractTableObject;
import com.fr.data.core.db.tableObject.ColumnSize;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class QuartzTables extends AbstractModuleTables
{
  public static void main(String[] paramArrayOfString)
  {
    new QuartzTables().loadSybaseCreateTableSql();
  }

  public void generatorModuleTables(Connection paramConnection)
  {
    if (DialectFactory.generateDialect(paramConnection) instanceof SybaseDialect)
    {
      if (new QRTZ_JOB_DETAILS(this, null).checkExist(paramConnection))
        return;
      Statement localStatement1 = null;
      try
      {
        List localList = loadSybaseCreateTableSql();
        Statement localStatement2 = paramConnection.createStatement();
        for (int i = 0; i < localList.size(); ++i)
        {
          String str = localList.get(i).toString();
          localStatement2.addBatch(str);
          FRContext.getLogger().log(Level.INFO, "Execute SQL: " + str);
        }
        localStatement2.executeBatch();
      }
      catch (SQLException localSQLException)
      {
        FRContext.getLogger().log(Level.SEVERE, localSQLException.getMessage(), localSQLException);
        DBUtils.closeStatement(localStatement1);
        localStatement1 = null;
      }
      finally
      {
        DBUtils.closeStatement(localStatement1);
        localStatement1 = null;
      }
      return;
    }
    super.generatorModuleTables(paramConnection);
    initQRTZ_LOCKSData(paramConnection);
  }

  protected void initTableObjectList()
  {
    this.tableObjectList.add(new QRTZ_JOB_DETAILS(this, null));
    this.tableObjectList.add(new QRTZ_JOB_LISTENERS(this, null));
    this.tableObjectList.add(new QRTZ_TRIGGERS(this, null));
    this.tableObjectList.add(new QRTZ_SIMPLE_TRIGGERS(this, null));
    this.tableObjectList.add(new QRTZ_CRON_TRIGGERS(this, null));
    this.tableObjectList.add(new QRTZ_BLOB_TRIGGERS(this, null));
    this.tableObjectList.add(new QRTZ_TRIGGER_LISTENERS(this, null));
    this.tableObjectList.add(new QRTZ_CALENDARS(this, null));
    this.tableObjectList.add(new QRTZ_PAUSED_TRIGGER_GRPS(this, null));
    this.tableObjectList.add(new QRTZ_FIRED_TRIGGERS(this, null));
    this.tableObjectList.add(new QRTZ_SCHEDULER_STATE(this, null));
    this.tableObjectList.add(new QRTZ_LOCKS(this, null));
  }

  public void removeModuleTables(Connection paramConnection)
  {
    this.droptableList.clear();
    this.droptableList.add(new QRTZ_JOB_LISTENERS(this, null));
    this.droptableList.add(new QRTZ_SIMPLE_TRIGGERS(this, null));
    this.droptableList.add(new QRTZ_CRON_TRIGGERS(this, null));
    this.droptableList.add(new QRTZ_BLOB_TRIGGERS(this, null));
    this.droptableList.add(new QRTZ_TRIGGER_LISTENERS(this, null));
    this.droptableList.add(new QRTZ_CALENDARS(this, null));
    this.droptableList.add(new QRTZ_PAUSED_TRIGGER_GRPS(this, null));
    this.droptableList.add(new QRTZ_FIRED_TRIGGERS(this, null));
    this.droptableList.add(new QRTZ_SCHEDULER_STATE(this, null));
    this.droptableList.add(new QRTZ_LOCKS(this, null));
    this.droptableList.add(new QRTZ_TRIGGERS(this, null));
    this.droptableList.add(new QRTZ_JOB_DETAILS(this, null));
    super.removeModuleTables(paramConnection);
  }

  private List loadSybaseCreateTableSql()
  {
    ArrayList localArrayList = new ArrayList();
    String[] arrayOfString = BaseUtils.readResourceAsString("com/fr/web/platform/tables/tables_sybase.sql").split("go");
    for (int i = 0; i < arrayOfString.length; ++i)
    {
      String str = arrayOfString[i].replaceAll("/\\*.*", "").trim();
      str = str.replaceAll("IF.*", "").trim();
      if (!(str.equals("")))
        localArrayList.add(str);
    }
    return localArrayList;
  }

  private void initQRTZ_LOCKSData(Connection paramConnection)
  {
    Statement localStatement = null;
    ResultSet localResultSet = null;
    try
    {
      localStatement = paramConnection.createStatement();
      localResultSet = localStatement.executeQuery("SELECT * FROM QRTZ_LOCKS");
      if (localResultSet.next())
      {
        jsr 59;
        return;
      }
    }
    catch (SQLException localSQLException1)
    {
      try
      {
        localResultSet.close();
        localStatement.close();
      }
      catch (Exception localException1)
      {
        FRContext.getLogger().log(Level.WARNING, localException1.getMessage(), localException1);
      }
    }
    finally
    {
      try
      {
        if (localResultSet != null)
          localResultSet.close();
        if (localStatement != null)
          localStatement.close();
      }
      catch (Exception localException2)
      {
        FRContext.getLogger().log(Level.WARNING, localException2.getMessage(), localException2);
      }
    }
    try
    {
      localStatement = paramConnection.createStatement();
      localStatement.addBatch("INSERT INTO QRTZ_LOCKS values('TRIGGER_ACCESS')");
      localStatement.addBatch("INSERT INTO QRTZ_LOCKS values('JOB_ACCESS')");
      localStatement.addBatch("INSERT INTO QRTZ_LOCKS values('CALENDAR_ACCESS')");
      localStatement.addBatch("INSERT INTO QRTZ_LOCKS values('STATE_ACCESS')");
      localStatement.addBatch("INSERT INTO QRTZ_LOCKS values('MISFIRE_ACCESS')");
      localStatement.executeBatch();
      localStatement.close();
    }
    catch (SQLException localSQLException2)
    {
      try
      {
        localStatement.close();
      }
      catch (SQLException localSQLException3)
      {
        FRContext.getLogger().log(Level.WARNING, localSQLException3.getMessage(), localSQLException3);
      }
    }
  }

  private class QRTZ_LOCKS extends AbstractTableObject
  {
    private final QuartzTables this$0;

    private QRTZ_LOCKS()
    {
      this.this$0 = paramQuartzTables;
    }

    public void initColumns()
    {
      addColumn("LOCK_NAME", 12, new ColumnSize(40), false, true);
    }

    public String foreignReference()
    {
      return null;
    }

    public Table getTable()
    {
      return new Table("QRTZ_LOCKS");
    }

    QRTZ_LOCKS(, QuartzTables.1 param1)
    {
      this(paramQuartzTables);
    }
  }

  private class QRTZ_SCHEDULER_STATE extends AbstractTableObject
  {
    private final QuartzTables this$0;

    private QRTZ_SCHEDULER_STATE()
    {
      this.this$0 = paramQuartzTables;
    }

    public void initColumns()
    {
      addColumn("INSTANCE_NAME", 12, new ColumnSize(200), false, true);
      addColumn("LAST_CHECKIN_TIME", -5, new ColumnSize(13), false);
      addColumn("CHECKIN_INTERVAL", -5, new ColumnSize(13), false);
    }

    public String foreignReference()
    {
      return null;
    }

    public Table getTable()
    {
      return new Table("QRTZ_SCHEDULER_STATE");
    }

    QRTZ_SCHEDULER_STATE(, QuartzTables.1 param1)
    {
      this(paramQuartzTables);
    }
  }

  private class QRTZ_FIRED_TRIGGERS extends AbstractTableObject
  {
    private final QuartzTables this$0;

    private QRTZ_FIRED_TRIGGERS()
    {
      this.this$0 = paramQuartzTables;
    }

    public void initColumns()
    {
      addColumn("ENTRY_ID", 12, new ColumnSize(95), false, true);
      addColumn("TRIGGER_NAME", 12, new ColumnSize(200), false);
      addColumn("TRIGGER_GROUP", 12, new ColumnSize(200), false);
      addColumn("IS_VOLATILE", -7, new ColumnSize(1), false);
      addColumn("INSTANCE_NAME", 12, new ColumnSize(200), false);
      addColumn("FIRED_TIME", -5, new ColumnSize(13), false);
      addColumn("PRIORITY", 4, new ColumnSize(13), false);
      addColumn("STATE", 12, new ColumnSize(16), false);
      addColumn("JOB_NAME", 12, new ColumnSize(200));
      addColumn("JOB_GROUP", 12, new ColumnSize(200));
      addColumn("IS_STATEFUL", -7, new ColumnSize(1));
      addColumn("REQUESTS_RECOVERY", -7, new ColumnSize(1));
    }

    public String foreignReference()
    {
      return null;
    }

    public Table getTable()
    {
      return new Table("QRTZ_FIRED_TRIGGERS");
    }

    QRTZ_FIRED_TRIGGERS(, QuartzTables.1 param1)
    {
      this(paramQuartzTables);
    }
  }

  private class QRTZ_PAUSED_TRIGGER_GRPS extends AbstractTableObject
  {
    private final QuartzTables this$0;

    private QRTZ_PAUSED_TRIGGER_GRPS()
    {
      this.this$0 = paramQuartzTables;
    }

    public void initColumns()
    {
      addColumn("TRIGGER_GROUP", 12, new ColumnSize(200), false, true);
    }

    public String foreignReference()
    {
      return null;
    }

    public Table getTable()
    {
      return new Table("QRTZ_PAUSED_TRIGGER_GRPS");
    }

    QRTZ_PAUSED_TRIGGER_GRPS(, QuartzTables.1 param1)
    {
      this(paramQuartzTables);
    }
  }

  private class QRTZ_CALENDARS extends AbstractTableObject
  {
    private final QuartzTables this$0;

    private QRTZ_CALENDARS()
    {
      this.this$0 = paramQuartzTables;
    }

    public void initColumns()
    {
      addColumn("CALENDAR_NAME", 12, new ColumnSize(200), false, true);
      addColumn("CALENDAR", 2004, new ColumnSize(2000), false);
    }

    public String foreignReference()
    {
      return null;
    }

    public Table getTable()
    {
      return new Table("QRTZ_CALENDARS");
    }

    QRTZ_CALENDARS(, QuartzTables.1 param1)
    {
      this(paramQuartzTables);
    }
  }

  private class QRTZ_TRIGGER_LISTENERS extends AbstractTableObject
  {
    private final QuartzTables this$0;

    private QRTZ_TRIGGER_LISTENERS()
    {
      this.this$0 = paramQuartzTables;
    }

    public void initColumns()
    {
      addColumn("TRIGGER_NAME", 12, new ColumnSize(200), false, true, true, false);
      addColumn("TRIGGER_GROUP", 12, new ColumnSize(200), false, true, true, false);
      addColumn("TRIGGER_LISTENER", 12, new ColumnSize(200), false, true);
    }

    public String foreignReference()
    {
      return "QRTZ_TRIGGERS(TRIGGER_NAME,TRIGGER_GROUP)";
    }

    public Table getTable()
    {
      return new Table("QRTZ_TRIGGER_LISTENERS");
    }

    QRTZ_TRIGGER_LISTENERS(, QuartzTables.1 param1)
    {
      this(paramQuartzTables);
    }
  }

  private class QRTZ_BLOB_TRIGGERS extends AbstractTableObject
  {
    private final QuartzTables this$0;

    private QRTZ_BLOB_TRIGGERS()
    {
      this.this$0 = paramQuartzTables;
    }

    public void initColumns()
    {
      addColumn("TRIGGER_NAME", 12, new ColumnSize(200), false, true, true, false);
      addColumn("TRIGGER_GROUP", 12, new ColumnSize(200), false, true, true, false);
      addColumn("BLOB_DATA", 2004, new ColumnSize(2000));
    }

    public String foreignReference()
    {
      return "QRTZ_TRIGGERS(TRIGGER_NAME,TRIGGER_GROUP)";
    }

    public Table getTable()
    {
      return new Table("QRTZ_BLOB_TRIGGERS");
    }

    QRTZ_BLOB_TRIGGERS(, QuartzTables.1 param1)
    {
      this(paramQuartzTables);
    }
  }

  private class QRTZ_CRON_TRIGGERS extends AbstractTableObject
  {
    private final QuartzTables this$0;

    private QRTZ_CRON_TRIGGERS()
    {
      this.this$0 = paramQuartzTables;
    }

    public void initColumns()
    {
      addColumn("TRIGGER_NAME", 12, new ColumnSize(200), false, true, true, false);
      addColumn("TRIGGER_GROUP", 12, new ColumnSize(200), false, true, true, false);
      addColumn("CRON_EXPRESSION", 12, new ColumnSize(120), false);
      addColumn("TIME_ZONE_ID", 12, new ColumnSize(80));
    }

    public String foreignReference()
    {
      return "QRTZ_TRIGGERS(TRIGGER_NAME,TRIGGER_GROUP)";
    }

    public Table getTable()
    {
      return new Table("QRTZ_CRON_TRIGGERS");
    }

    QRTZ_CRON_TRIGGERS(, QuartzTables.1 param1)
    {
      this(paramQuartzTables);
    }
  }

  private class QRTZ_SIMPLE_TRIGGERS extends AbstractTableObject
  {
    private final QuartzTables this$0;

    private QRTZ_SIMPLE_TRIGGERS()
    {
      this.this$0 = paramQuartzTables;
    }

    public void initColumns()
    {
      addColumn("TRIGGER_NAME", 12, new ColumnSize(200), false, true, true, false);
      addColumn("TRIGGER_GROUP", 12, new ColumnSize(200), false, true, true, false);
      addColumn("REPEAT_COUNT", -5, new ColumnSize(7), false);
      addColumn("REPEAT_INTERVAL", -5, new ColumnSize(12), false);
      addColumn("TIMES_TRIGGERED", -5, new ColumnSize(10), false);
    }

    public String foreignReference()
    {
      return "QRTZ_TRIGGERS(TRIGGER_NAME,TRIGGER_GROUP)";
    }

    public Table getTable()
    {
      return new Table("QRTZ_SIMPLE_TRIGGERS");
    }

    QRTZ_SIMPLE_TRIGGERS(, QuartzTables.1 param1)
    {
      this(paramQuartzTables);
    }
  }

  private class QRTZ_TRIGGERS extends AbstractTableObject
  {
    private final QuartzTables this$0;

    private QRTZ_TRIGGERS()
    {
      this.this$0 = paramQuartzTables;
    }

    public void initColumns()
    {
      addColumn("TRIGGER_NAME", 12, new ColumnSize(200), false, true);
      addColumn("TRIGGER_GROUP", 12, new ColumnSize(200), false, true);
      addColumn("JOB_NAME", 12, new ColumnSize(200), false, false, true, false);
      addColumn("JOB_GROUP", 12, new ColumnSize(200), false, false, true, false);
      addColumn("IS_VOLATILE", -7, new ColumnSize(1), false);
      addColumn("DESCRIPTION", 12, new ColumnSize(250));
      addColumn("NEXT_FIRE_TIME", -5, new ColumnSize(13));
      addColumn("PREV_FIRE_TIME", -5, new ColumnSize(13));
      addColumn("PRIORITY", 4, new ColumnSize(13));
      addColumn("TRIGGER_STATE", 12, new ColumnSize(16), false);
      addColumn("TRIGGER_TYPE", 12, new ColumnSize(8), false);
      addColumn("START_TIME", -5, new ColumnSize(13), false);
      addColumn("END_TIME", -5, new ColumnSize(13));
      addColumn("CALENDAR_NAME", 12, new ColumnSize(200));
      addColumn("MISFIRE_INSTR", 5, new ColumnSize(2));
      addColumn("JOB_DATA", 2004, new ColumnSize(2000));
    }

    public String foreignReference()
    {
      return "QRTZ_JOB_DETAILS(JOB_NAME,JOB_GROUP)";
    }

    public Table getTable()
    {
      return new Table("QRTZ_TRIGGERS");
    }

    QRTZ_TRIGGERS(, QuartzTables.1 param1)
    {
      this(paramQuartzTables);
    }
  }

  private class QRTZ_JOB_LISTENERS extends AbstractTableObject
  {
    private final QuartzTables this$0;

    private QRTZ_JOB_LISTENERS()
    {
      this.this$0 = paramQuartzTables;
    }

    public void initColumns()
    {
      addColumn("JOB_NAME", 12, new ColumnSize(200), false, true, true, false);
      addColumn("JOB_GROUP", 12, new ColumnSize(200), false, true, true, false);
      addColumn("JOB_LISTENER", 12, new ColumnSize(200), false, true);
    }

    public String foreignReference()
    {
      return "QRTZ_JOB_DETAILS(JOB_NAME,JOB_GROUP)";
    }

    public Table getTable()
    {
      return new Table("QRTZ_JOB_LISTENERS");
    }

    QRTZ_JOB_LISTENERS(, QuartzTables.1 param1)
    {
      this(paramQuartzTables);
    }
  }

  private class QRTZ_JOB_DETAILS extends AbstractTableObject
  {
    private final QuartzTables this$0;

    private QRTZ_JOB_DETAILS()
    {
      this.this$0 = paramQuartzTables;
    }

    public void initColumns()
    {
      addColumn("JOB_NAME", 12, new ColumnSize(200), false, true);
      addColumn("JOB_GROUP", 12, new ColumnSize(200), false, true);
      addColumn("DESCRIPTION", 12, new ColumnSize(250));
      addColumn("JOB_CLASS_NAME", 12, new ColumnSize(250), false);
      addColumn("IS_DURABLE", -7, new ColumnSize(1), false);
      addColumn("IS_VOLATILE", -7, new ColumnSize(1), false);
      addColumn("IS_STATEFUL", -7, new ColumnSize(1), false);
      addColumn("REQUESTS_RECOVERY", 12, new ColumnSize(1), false);
      addColumn("JOB_DATA", 2004, new ColumnSize(2000));
    }

    public String foreignReference()
    {
      return null;
    }

    public Table getTable()
    {
      return new Table("QRTZ_JOB_DETAILS");
    }

    QRTZ_JOB_DETAILS(, QuartzTables.1 param1)
    {
      this(paramQuartzTables);
    }
  }
}